********************************************************************************
***
*** 	Replication files for Zhuang, Maiting. 2022.
***
*** 	"Intergovernmental Conflict and Censorship: Evidence from China's 
***
***		Anti-Corruption Campaign" 
***
***		Journal of the European Economic Association
***
********************************************************************************

*** 	Do-file for all charts tables in main text 
***
***		(except those based on the official-newspaper-day panel)

********************************************************************************

clear

global dir "your directory path"
cd "$dir"


********************************************************************************

*** TABLE 1

*** Newspaper articles

use "$dir/data/chartdata.dta",clear

gen period=1 if date_diff==1
replace period=2 if date_diff>=2 & date_diff<=9
replace period=3 if date_diff>=10 & date_diff<=364
replace period=4 if date_diff<0

forval i=1/4{
gen index_p`i'=article_mean_split if period==`i'
}

estpost tabstat index_p* if  own_province==1 & of_high==1, statistics(mean) columns(variables)
esttab using "$dir/output/Table1.csv", plain replace cells("index_p1 index_p2 index_p3 index_p4") mtitles("Day1" "Day2to9" "Day10on" "Pre") nonumber noobs title("articles, own_province==1 & of_high==1")
estpost tabstat index_p* if  own_province==0 & of_high==1, statistics(mean) columns(variables)
esttab using "$dir/output/Table1.csv", plain append cells("index_p1 index_p2 index_p3 index_p4") mtitles("Day1" "Day2to9" "Day10on" "Pre") nonumber noobs title("articles, own_province==0 & of_high==1")
estpost tabstat index_p* if  own_province==1 & of_high==0, statistics(mean) columns(variables)
esttab using "$dir/output/Table1.csv", plain append cells("index_p1 index_p2 index_p3 index_p4") mtitles("Day1" "Day2to9" "Day10on" "Pre")  nonumber noobs title("articles, own_province==1 & of_high==0")
estpost tabstat index_p* if  own_province==0 & of_high==0, statistics(mean) columns(variables)
esttab using "$dir/output/Table1.csv", plain append cells("index_p1 index_p2 index_p3 index_p4") mtitles("Day1" "Day2to9" "Day10on" "Pre")  nonumber noobs title("articles, own_province==0 & of_high==0")


*** Baidu index

use "$dir/data/baidu.dta",clear

keep if np_sample==1

gen period=1 if date_diff==0
replace period=2 if date_diff>=1 & date_diff<=9
replace period=3 if date_diff>=10 & date_diff<=364

forval i=1/3{
gen index_p`i'=index if period==`i'
}

estpost tabstat index_p* if  own_province==1  & of_high==1, statistics(mean) columns(variables)
esttab using "$dir/output/Table1.csv", plain append cells("index_p1 index_p2 index_p3") mtitles("Day1" "Day2to9" "Day10on") nonumber noobs title("Baidu, own_province==1 & of_high==1")
estpost tabstat index_p* if  own_province==0  & of_high==1, statistics(mean) columns(variables)
esttab using "$dir/output/Table1.csv", plain append cells("index_p1 index_p2 index_p3") mtitles("Day1" "Day2to9" "Day10on")  nonumber noobs title("Baidu, own_province==0 & of_high==1")


*** Sina Weibo

use "$dir/data/sinaweibo.dta",clear

estpost tabstat count_w_p if c_u_of_own_province_dum==1 & c_u_np_own_province==0, statistics(mean) columns(variables)
esttab using "$dir/output/Table1.csv", plain append cells("count_w_p") mtitle("post") nonumber noobs title("Sina Weibo, own_province==1 & of_high==1")
estpost tabstat count_w_p if  c_u_of_own_province_dum==0 & c_u_np_own_province==0, statistics(mean) columns(variables)
esttab using "$dir/output/Table1.csv", plain append cells("count_w_p") mtitle("post") nonumber noobs title("Sina Weibo, own_province==0 & of_high==1")


/*

Entries for Table 1 are calculated based on the output of Table1.csv

Row 1 corresponds to Table1.csv row 4 (for columns B to D)
Row 2 corresponds to Table1.csv row 8 (for columns B to D)
Row 3 corresponds to Table1.csv row4/row8 (for columns B to D)

Row 4 corresponds to Table1.csv (row4/row8) / (row12/row16) (for columns B to D)
Row 5 corresponds to Table1.csv (row4/row8) / ((row12/row16) * Adj) (for columns B to D) where Adj is calculated as (row4/row8) / (row12/row16) for column E
Row 6 corresponds to Table1.csv (row4/row8) / (row12/row16) (for columns B to D)
Row 7 corresponds to Table1.csv (row4/row8) / Adj2 (for columns B to D) where Adj2 is calculated as row28/row2 for column B

*/

********************************************************************************

*** TABLE 3

use  "$dir/data/articles.dta",clear

set matsize 1100

keep if art_post==1

egen np = group(np_name_cons)

set more off
estimates clear
label variable share_oh "\shortstack[l]{Share of high-level officials\\from same province}"
label variable share_ol "\shortstack[l]{Share of low-level officials\\from same province}"
label variable share_high "\shortstack[l]{Share of high-level officials}"

foreach x in art_words art_articles_bal art_multipleofficial art_txtdenounce art_headline_copy art_hlcorrupt art_hlccdi {
areg `x' share_oh share_ol share_high date_cny_broad date_duanwu_broad date_zhongqiu_broad date_congress date_committee date_renda date_zhengxie ccpprov lhprov i.dofw i.month i.year dum_*, absorb(np ) vce(cluster np)
estadd ysumm
estimates store model`x'
}
esttab model* using "$dir/output/Table3.tex", ///
	refcat(share_ol " " share_ol " ", below nolabel) ///
	drop(*.dofw *.month *.year date_* lhprov dum_* _cons) b(a2) se(a2) /// 
	replace label interaction(" x ") star(* 0.10 ** 0.05 *** 0.01) booktabs noomitted nobaselevels noobs ///
	fragment nonumbers nolines nodepvar nomtitle ///
	stats(N r2 ymean,  fmt(%16.0fc a2 a2 ) label(  "No. of obs." "R-squared" "Mean dep. var.")) 
	
********************************************************************************

*** TABLE 4

use "$dir/data/baidu.dta",clear

keep if ac==1

merge m:1 date province_name using "$dir/data/of_timeline.dta"
drop if _merge==2

quietly describe c_of*,varlist
local master `r(varlist)'
foreach x of local master{
replace `x'=0 if _merge==1
}

drop _merge

xtset province_code date

label variable c_of_low "\shortstack[l]{Number of low-level officials\\from same province investigated}"
label variable c_of_high "\shortstack[l]{Number of high-level officials\\from same province investigated}"

*

merge 1:1 date province_name using  "$dir/data/art_timeline.dta"
drop if _merge==2

quietly describe  nps* ,varlist
local master `r(varlist)'
foreach x of local master{
replace `x'=0 if _merge==1
}

drop _merge

*

merge 1:1 date province_name using "$dir/data/np_timeline.dta"
drop if _merge==2

replace np_count_prov=0 if _merge==1

drop _merge

quietly describe nps* ,varlist
local master `r(varlist)'
foreach x of local master{
gen frac_`x'=`x'/np_count_prov
}
rename frac_nps* frac*

label variable c_of_low "\shortstack[l]{Number of low-level officials\\from same province investigated}"
label variable c_of_high "\shortstack[l]{Number of high-level officials\\from same province investigated}"
label variable frac_ownlow "\shortstack[l]{...Low-level officials\\from same province}"
label variable frac_ownhigh "\shortstack[l]{...High-level officials\\from same province}"
label variable frac_nownlow "\shortstack[l]{...Low-level officials\\from other provinces}"
label variable frac_nownhigh "\shortstack[l]{...High-level officials\\from other provinces}"
label variable frac_denounce "\shortstack[l]{...references to citizen\\complaints}"
label variable frac_corrupt "\shortstack[l]{...\textquote{Corruption} in headline}"
label variable frac_ccdi "\shortstack[l]{...\textquote{Anti-Corruption Campaign}\\in headline}"

set more off
estimates clear

areg index  c_of_high  c_of_low i.province_code if  np_sample==1  & date<=td(31dec2014) ,absorb(date) 
estadd ysumm
estimates store model_announce
areg index c_of_high  c_of_low frac_ownhigh frac_ownlow  frac_nownhigh  frac_nownlow i.province_code if np_sample==1  & date<=td(31dec2014) ,absorb(date) robust
estadd ysumm
estimates store model_fracs
areg index c_of_high  c_of_low frac_denounce i.province_code if np_sample==1  & date<=td(31dec2014) ,absorb(date) robust
estadd ysumm
estimates store model_den
areg index c_of_high  c_of_low frac_corrupt i.province_code if np_sample==1  & date<=td(31dec2014) ,absorb(date) robust
estadd ysumm
estimates store model_corrupt
areg index c_of_high  c_of_low frac_ccdi i.province_code if np_sample==1  & date<=td(31dec2014) ,absorb(date) robust
estadd ysumm
estimates store model_ccdi

esttab model* using "$dir/output/Table4.tex", ///
	refcat(frac_ophigh "\shortstack[l]{ \\ \\Fraction of own-province newspapers\\reporting about scandals of...}" ///
	frac_denounce "\shortstack[l]{ \\ \\Fraction of own-province newspapers\\publishing articles with...}",  nolabel) ///
	drop(*province_code _cons) b(a2) se(a2) /// 
	replace label interaction(" x ") star(* 0.10 ** 0.05 *** 0.01) booktabs noomitted nobaselevels noobs ///
	fragment nonumbers nolines nodepvar nomtitle ///
	stats(N r2 ymean,  fmt(%16.0fc a2 a2 ) label(  "No. of obs." "R-squared" "Mean dep. var.")) 

********************************************************************************

*** TABLE 5

set more off

use "$dir/data/sinaweibo.dta",clear

estimates clear
areg  count_w_p  c_u_of_own_province_dum c_u_np_own_province mid_num_of dum_* i.c_u_provincecode ///
i.dofw i.month i.year date_cny_broad date_duanwu_broad date_zhongqiu_broad date_congress date_committee date_renda date_zhengxie ccpprov lhprov ///
, absorb(np) vce(clust np)
estadd ysumm
estimates store m1
areg   mintime_w_p c_u_of_own_province_dum c_u_np_own_province mid_num_of dum_* i.c_u_provincecode ///
i.dofw i.month i.year date_cny_broad date_duanwu_broad date_zhongqiu_broad date_congress date_committee date_renda date_zhengxie ccpprov lhprov ///
, absorb(np) vce(clust np)
estadd ysumm
estimates store m2
areg  count_w_p  c_u_of_own_province_dum c_u_np_own_province i.c_u_provincecode , absorb(mid) vce(clust np)
estadd ysumm
estimates store m3
areg   mintime_w_p c_u_of_own_province_dum c_u_np_own_province i.c_u_provincecode, absorb(mid) vce(clust np)
estadd ysumm
estimates store m4


esttab m1 m3 m2 m4  using "$dir/output/Table5.tex" , keep(c_u_np_own_province c_u_of_own_province_dum) ///
	refcat(c_u_np_own_province " " c_u_of_own_province_dum " ", below nolabel) ///
	b(a2) se(a2) /// 
	prefoot(`"\addlinespace"' ///
		`"\shortstack[l]{Number of high-level\\officials mentioned}		 & \checkmark &  & \checkmark  &  \\"' ///
	`"Seasonal controls		 & \checkmark &  & \checkmark  &  \\"' ///
	`"User province FE		& \checkmark & \checkmark  & \checkmark  & \checkmark  \\ "' ///
	`"Newspaper FE		& \checkmark &   & \checkmark  &   \\ "' ///
	`"Official FE		& \checkmark &   & \checkmark  &   \\ "' ///
	`"Weibo post FE		& & \checkmark   &  & \checkmark   \\ "' ///
	`"\midrule"') ///
	replace label  star(* 0.10 ** 0.05 *** 0.01) booktabs noomitted nobaselevels noobs ///
	fragment nonumbers nolines nodepvar nomtitle ///
	stats(N r2 ymean,  fmt(%16.0fc a2 a2 ) label(  "No. of obs." "R-squared" "Mean dep. var.")) 
	
********************************************************************************

*** FIGURE 1 

* Panels A and C

use "$dir/data/chartdata.dta"

line article_mean_split date_diff if own_province==1 & of_high==1,  || ///
line article_mean_split date_diff if own_province==0 & of_high==1 , lpattern(dash)  || ///
if date_diff>=-10&date_diff<=10 , scheme(s1mono) xscale(range(-10(2)10)) xlabel(-10(2)10) yscale(range(0(0.1)0.4)) ylabel(0(0.1)0.4) ///
	legend(order(1 "Same province" 2 "Other province")) ///
	xline(0,lcolor(gs10) lwidth(thin)) xtitle("Days since investigation announcement" , margin(medium)) ///
	ytitle("Fraction of newspapers with articles" "about each official", margin(medium)) 
graph export "$dir/output/Figure1a.pdf",  replace

line article_mean_split date_diff if own_province==1 & of_high==0,  || ///
line article_mean_split date_diff if own_province==0 & of_high==0,  lpattern(dash) || ///
if date_diff>=-10&date_diff<=10 , scheme(s1mono) xscale(range(-10(2)10)) xlabel(-10(2)10) yscale(range(0(0.1)0.4)) ylabel(0(0.1)0.4)  ///
	legend(order(1 "Same province" 2 "Other province")) ///
	xline(0,lcolor(gs10) lwidth(thin)) xtitle("Days since investigation announcement" , margin(medium)) ///
	ytitle("Fraction of newspapers with articles" "about each official", margin(medium)) 
graph export "$dir/output/Figure1c.pdf",  replace


*** Panels B and D

preserve

use "$dir/data/baidu.dta"

drop if ac==1
keep if np_sample==1
keep if date_diff>=-10&date_diff<=10 

bys date_diff own_province of_high: egen ind_mean=mean(index)

duplicates drop date_diff own_province of_high,force

sort own_province date_diff of_high

keep ind_mean own_province date_diff of_high

line ind_mean date_diff  if own_province==1 & of_high==0 ,lcolor(black)  || line ind_mean date_diff  if own_province==0 & of_high==0, lpattern(dash) || if date_diff>=-10&date_diff<=10 , scheme(s1mono) xscale(range(-10(2)10)) xlabel(-10(2)10) ///
	legend(order(1 "Same province" 2 "Other province")) ytitle("Number of internet searches", margin(medium)) ///
	xline(0,lcolor(gs10) lwidth(thin)) xtitle("Days since investigation announcement" , margin(medium)) ysc(r(0(5000)20000)) ylabel(0(5000)20000)
graph export "$dir/output/Figured.pdf",  replace

line ind_mean date_diff  if own_province==1 & of_high==1 ,lcolor(black)  || line ind_mean date_diff  if own_province==0 &of_high==1 , lpattern(dash) || if date_diff>=-10&date_diff<=10 , scheme(s1mono) xscale(range(-10(2)10)) xlabel(-10(2)10) ///
	legend(order(1 "Same province" 2 "Other province")) ytitle("Number of internet searches", margin(medium)) ///
	xline(0,lcolor(gs10) lwidth(thin)) xtitle("Days since investigation announcement" , margin(medium))
graph export "$dir/output/Figure1b.pdf",  replace

restore


********************************************************************************





